<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>初步了解编辑器拓展 | Hotaru Hikari's Blog</title><meta name="keywords" content="Unity,编辑器拓展"><meta name="author" content="螢の光"><meta name="copyright" content="螢の光"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content=":::info前言：记录一下初步接触编辑器拓展相关的内容。::: 拓展Project视图拓展Project将选中物体的名字打印出来，第三个参数代表排序顺序。 12345678910[MenuItem(&quot;Assets&#x2F;My Tools&#x2F;Tools 1&quot;, false, 2)]static void MyTools1()&amp;#123;    Debug.Log(Selection.a">
<meta property="og:type" content="article">
<meta property="og:title" content="初步了解编辑器拓展">
<meta property="og:url" content="https://hotarunohikari.gitee.io/hotaru-no-hikari/2021/10/24/%E5%88%9D%E6%AD%A5%E4%BA%86%E8%A7%A3%E7%BC%96%E8%BE%91%E5%99%A8%E6%8B%93%E5%B1%95/index.html">
<meta property="og:site_name" content="Hotaru Hikari&#39;s Blog">
<meta property="og:description" content=":::info前言：记录一下初步接触编辑器拓展相关的内容。::: 拓展Project视图拓展Project将选中物体的名字打印出来，第三个参数代表排序顺序。 12345678910[MenuItem(&quot;Assets&#x2F;My Tools&#x2F;Tools 1&quot;, false, 2)]static void MyTools1()&amp;#123;    Debug.Log(Selection.a">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://hotarunohikari.gitee.io/hotaru-no-hikari/img/cover2.jpg">
<meta property="article:published_time" content="2021-10-24T15:30:09.000Z">
<meta property="article:modified_time" content="2021-10-25T06:40:54.088Z">
<meta property="article:author" content="螢の光">
<meta property="article:tag" content="Unity">
<meta property="article:tag" content="编辑器拓展">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://hotarunohikari.gitee.io/hotaru-no-hikari/img/cover2.jpg"><link rel="shortcut icon" href="/hotaru-no-hikari/img/avatar.jpg"><link rel="canonical" href="https://hotarunohikari.gitee.io/hotaru-no-hikari/2021/10/24/%E5%88%9D%E6%AD%A5%E4%BA%86%E8%A7%A3%E7%BC%96%E8%BE%91%E5%99%A8%E6%8B%93%E5%B1%95/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/hotaru-no-hikari/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/hotaru-no-hikari/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery@2/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '初步了解编辑器拓展',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-10-25 14:40:54'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/style.css"><link rel="stylesheet" href="/css/remixicon.css"><meta name="generator" content="Hexo 6.2.0"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/hotaru-no-hikari/img/avatar.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/hotaru-no-hikari/archives/"><div class="headline">文章</div><div class="length-num">9</div></a><a href="/hotaru-no-hikari/tags/"><div class="headline">标签</div><div class="length-num">9</div></a><a href="/hotaru-no-hikari/categories/"><div class="headline">分类</div><div class="length-num">13</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/"><i class="fa-fw ri-home-wifi-line"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/bangumis/"><i class="fa-fw fas fa-folder-open"></i><span> 追番</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 链接</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/hotaru-no-hikari/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></li><li><a class="site-page child" href="/hotaru-no-hikari/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('/hotaru-no-hikari/img/cover2.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/hotaru-no-hikari/">Hotaru Hikari's Blog</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/"><i class="fa-fw ri-home-wifi-line"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/hotaru-no-hikari/bangumis/"><i class="fa-fw fas fa-folder-open"></i><span> 追番</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-list"></i><span> 链接</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/hotaru-no-hikari/link/"><i class="fa-fw fas fa-link"></i><span> 友链</span></a></li><li><a class="site-page child" href="/hotaru-no-hikari/about/"><i class="fa-fw fas fa-heart"></i><span> 关于</span></a></li></ul></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">初步了解编辑器拓展</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-10-24T15:30:09.000Z" title="发表于 2021-10-24 23:30:09">2021-10-24</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-10-25T06:40:54.088Z" title="更新于 2021-10-25 14:40:54">2021-10-25</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/hotaru-no-hikari/categories/%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91/">游戏开发</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/hotaru-no-hikari/categories/%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91/Unity/">Unity</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/hotaru-no-hikari/categories/%E6%B8%B8%E6%88%8F%E5%BC%80%E5%8F%91/Unity/%E7%BC%96%E8%BE%91%E5%99%A8%E6%8B%93%E5%B1%95/">编辑器拓展</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">2.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>13分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="初步了解编辑器拓展"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><p>:::info<br>前言：记录一下初步接触编辑器拓展相关的内容。<br>:::</p>
<h1 id="拓展Project视图"><a href="#拓展Project视图" class="headerlink" title="拓展Project视图"></a>拓展Project视图</h1><h2 id="拓展Project"><a href="#拓展Project" class="headerlink" title="拓展Project"></a>拓展Project</h2><p>将选中物体的名字打印出来，第三个参数代表排序顺序。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Assets/My Tools/Tools 1&quot;</span>, false, 2)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">MyTools1</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    Debug.Log(Selection.activeObject.name);</span><br><span class="line">&#125;</span><br><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Assets/My Tools/Tools 2&quot;</span>, false, 1)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">MyTools2</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    Debug.Log(Selection.activeObject.name);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="对Create进行拓展"><a href="#对Create进行拓展" class="headerlink" title="对Create进行拓展"></a>对Create进行拓展</h2><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Assets/Create/My Create/Cube&quot;</span>, false,2)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">CreateCube</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    GameObject.CreatePrimitive(PrimitiveType.Cube);</span><br><span class="line">&#125;</span><br><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Assets/Create/My Create/Sphere&quot;</span>, false, 2)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">CreateSphere</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    GameObject.CreatePrimitive(PrimitiveType.Sphere);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="布局拓展"><a href="#布局拓展" class="headerlink" title="布局拓展"></a>布局拓展</h2><p>选中一个资源后，会在右方显示一个click按钮，点击后在console面板打印对应的资源名。<br><code>InitializeOnLoadMethod</code>特性使该方法在C#每次编译完成后首先调用。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">InitializeOnLoadMethod</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">InitializeOnLoadMethod</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    EditorApplication.projectWindowItemOnGUI = <span class="built_in">delegate</span> (<span class="built_in">string</span> guid, Rect selectionRect)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//在project视图中选择一个资源</span></span><br><span class="line">        <span class="keyword">if</span> (Selection.activeObject &amp;&amp; guid == AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(Selection.activeObject)))</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">//设置拓展区域范围</span></span><br><span class="line">            <span class="built_in">float</span> width = <span class="number">50f</span>;</span><br><span class="line">            selectionRect.x += selectionRect.width - width;</span><br><span class="line">            selectionRect.y += <span class="number">2.0f</span>;</span><br><span class="line">            selectionRect.width = width;</span><br><span class="line">            GUI.color = Color.red;</span><br><span class="line">            <span class="comment">//点击事件</span></span><br><span class="line">            <span class="keyword">if</span> (GUI.Button(selectionRect, <span class="string">&quot;click&quot;</span>))</span><br><span class="line">            &#123;</span><br><span class="line">                Debug.LogFormat(<span class="string">&quot;click:&#123;0&#125;&quot;</span>, Selection.activeObject.name);</span><br><span class="line">            &#125;</span><br><span class="line">            GUI.color = Color.white;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h1 id="拓展Hierarchy视图"><a href="#拓展Hierarchy视图" class="headerlink" title="拓展Hierarchy视图"></a>拓展Hierarchy视图</h1><h2 id="拓展菜单"><a href="#拓展菜单" class="headerlink" title="拓展菜单"></a>拓展菜单</h2><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;GameObject/My Create/Cube&quot;</span>, false, 0)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">CreateCube</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    GameObject.CreatePrimitive(PrimitiveType.Cube);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="拓展布局"><a href="#拓展布局" class="headerlink" title="拓展布局"></a>拓展布局</h2><p>与前面类似</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">InitializeOnLoadMethod</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">InitializeOnLoadMethod</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    EditorApplication.hierarchyWindowItemOnGUI = <span class="built_in">delegate</span> (<span class="built_in">int</span> instanceID, Rect selectionRect)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//在hierarchy视图中选择一个资源</span></span><br><span class="line">        <span class="keyword">if</span> (Selection.activeObject &amp;&amp; instanceID == Selection.activeObject.GetInstanceID())</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">//设置拓展区域范围</span></span><br><span class="line">            <span class="built_in">float</span> width = <span class="number">50f</span>;</span><br><span class="line">            <span class="built_in">float</span> height = <span class="number">20f</span>;</span><br><span class="line">            selectionRect.x += selectionRect.width - width;</span><br><span class="line">            selectionRect.width = width;</span><br><span class="line">            selectionRect.height = height;</span><br><span class="line">            <span class="comment">//点击事件</span></span><br><span class="line">            <span class="keyword">if</span> (GUI.Button(selectionRect, <span class="string">&quot;click&quot;</span>))</span><br><span class="line">            &#123;</span><br><span class="line">                Debug.LogFormat(<span class="string">&quot;click:&#123;0&#125;&quot;</span>, Selection.activeObject.name);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="重写菜单"><a href="#重写菜单" class="headerlink" title="重写菜单"></a>重写菜单</h2><p>抛弃其它菜单，完全使用自己的菜单。<br>通过Event.current获取当前的事件。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Window/Test/game&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Test</span>()</span></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Window/Test/mmo&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Test1</span>()</span></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Window/Test/游戏/MMO&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Test2</span>()</span></span><br><span class="line">&#123;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">[<span class="meta">InitializeOnLoadMethod</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">StartInitializeOnLoadMethod</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    EditorApplication.hierarchyWindowItemOnGUI += OnHierachyGUI;</span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">OnHierachyGUI</span>(<span class="params"><span class="built_in">int</span> instanceID, Rect selectionRect</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">if</span> (Event.current != <span class="literal">null</span> &amp;&amp; selectionRect.Contains(Event.current.mousePosition)</span><br><span class="line">        &amp;&amp; Event.current.button == <span class="number">1</span> &amp;&amp; Event.current.type &lt;= EventType.MouseUp)</span><br><span class="line">    &#123;</span><br><span class="line">        GameObject selectedGameObject = EditorUtility.InstanceIDToObject(instanceID) <span class="keyword">as</span> GameObject;</span><br><span class="line">        <span class="comment">//判断selectedGameObject的条件</span></span><br><span class="line">        <span class="keyword">if</span> (selectedGameObject)</span><br><span class="line">        &#123;</span><br><span class="line">            Vector2 mousePosition = Event.current.mousePosition;</span><br><span class="line">            <span class="comment">//弹出自定义菜单</span></span><br><span class="line">            EditorUtility.DisplayPopupMenu(<span class="keyword">new</span> Rect(mousePosition.x, mousePosition.y, <span class="number">0</span>, <span class="number">0</span>), <span class="string">&quot;Window/Test&quot;</span>, <span class="literal">null</span>);</span><br><span class="line">            Event.current.Use(); <span class="comment">//不再执行原有操作</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="重写自带的Image组件"><a href="#重写自带的Image组件" class="headerlink" title="重写自带的Image组件"></a>重写自带的Image组件</h2><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;GameObject/UI/Image&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">CreatImage</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//查找到Canvas</span></span><br><span class="line">    <span class="keyword">if</span> (Selection.activeTransform.GetComponentInParent&lt;Canvas&gt;())</span><br><span class="line">    &#123;</span><br><span class="line">        Image image = <span class="keyword">new</span> GameObject(<span class="string">&quot;image&quot;</span>).AddComponent&lt;Image&gt;();</span><br><span class="line">        image.raycastTarget = <span class="literal">false</span>;</span><br><span class="line">        image.transform.SetParent(Selection.activeTransform, <span class="literal">false</span>);</span><br><span class="line">        Selection.activeTransform = image.transform;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="拓展Inspector视图"><a href="#拓展Inspector视图" class="headerlink" title="拓展Inspector视图"></a>拓展Inspector视图</h1><h2 id="拓展源生组件"><a href="#拓展源生组件" class="headerlink" title="拓展源生组件"></a>拓展源生组件</h2><p>对Camera进行拓展，但拓展组件只能加在源生组件的最上面或者最下面，不能插在中间。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">CustomEditor(typeof(Camera))</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">TestED</span> : <span class="title">Editor</span> </span><br><span class="line">&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">void</span> <span class="title">OnInspectorGUI</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span> (GUILayout.Button(<span class="string">&quot;拓展按钮&quot;</span>)) &#123; &#125;</span><br><span class="line">        <span class="keyword">base</span>.OnInspectorGUI();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="拓展继承组件"><a href="#拓展继承组件" class="headerlink" title="拓展继承组件"></a>拓展继承组件</h2><p>部分组件直接拓展会造成面板布局奇怪，可以通过反射获取TransformInspector，并重写OnInspectorGUI方法。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">CustomEditor(typeof(Transform))</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">TestED</span> : <span class="title">Editor</span> </span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">private</span> Editor m_Editor;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">OnEnable</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        m_Editor = Editor.CreateEditor(target, Assembly.GetAssembly(<span class="keyword">typeof</span>(Editor)).GetType(<span class="string">&quot;UnityEditor.TransformInspector&quot;</span>, <span class="literal">true</span>));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">void</span> <span class="title">OnInspectorGUI</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span> (GUILayout.Button(<span class="string">&quot;拓展按钮&quot;</span>)) &#123; &#125;</span><br><span class="line">        m_Editor.OnInspectorGUI();<span class="comment">//绘制原有信息</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="组件不可编辑"><a href="#组件不可编辑" class="headerlink" title="组件不可编辑"></a>组件不可编辑</h2><p>通过GUI.enabled &#x3D; false处理不可编辑的区域。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">CustomEditor(typeof(Transform))</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">TestED</span> : <span class="title">Editor</span> </span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">private</span> Editor m_Editor;</span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">OnEnable</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        m_Editor = Editor.CreateEditor(target, Assembly.GetAssembly(<span class="keyword">typeof</span>(Editor)).GetType(<span class="string">&quot;UnityEditor.TransformInspector&quot;</span>, <span class="literal">true</span>));</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">void</span> <span class="title">OnInspectorGUI</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">if</span> (GUILayout.Button(<span class="string">&quot;拓展按钮上&quot;</span>)) &#123; &#125;</span><br><span class="line">        GUI.enabled = <span class="literal">false</span>;</span><br><span class="line">        m_Editor.OnInspectorGUI();</span><br><span class="line">        GUI.enabled = <span class="literal">true</span>;</span><br><span class="line">        <span class="keyword">if</span> (GUILayout.Button(<span class="string">&quot;拓展按钮下&quot;</span>)) &#123; &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="Context菜单"><a href="#Context菜单" class="headerlink" title="Context菜单"></a>Context菜单</h2><p>将新菜单拓展到Transform组件上，如果想拓展到所有组件上可以改为Compoment。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;CONTEXT/Transform/New Context 1&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">NewContext1</span>(<span class="params">MenuCommand command</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    Debug.Log(command.context.name);</span><br><span class="line">&#125;</span><br><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;CONTEXT/Transform/New Context 2&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">NewContext2</span>(<span class="params">MenuCommand command</span>)</span></span><br><span class="line">&#123;</span><br><span class="line">    Debug.Log(command.context.name);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h1 id="拓展Scene视图"><a href="#拓展Scene视图" class="headerlink" title="拓展Scene视图"></a>拓展Scene视图</h1><h2 id="辅助元素"><a href="#辅助元素" class="headerlink" title="辅助元素"></a>辅助元素</h2><p>主要使用Gizmos工具的API，需要挂载到游戏物体上。只在编辑器下生效。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//需要选择对象</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">OnDrawGizmosSelected</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    Gizmos.color = Color.red;</span><br><span class="line">    <span class="comment">//画线</span></span><br><span class="line">    Gizmos.DrawLine(transform.position, Vector3.one);</span><br><span class="line">    <span class="comment">//立方体</span></span><br><span class="line">    Gizmos.DrawCube(Vector3.one, Vector3.one);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//始终显示</span></span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">OnDrawGizmos</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    Gizmos.DrawSphere(transform.position, <span class="number">1</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="辅助UI"><a href="#辅助UI" class="headerlink" title="辅助UI"></a>辅助UI</h2><p>继承Editor类，重写OnSceneGUI方法。<br>EditorGUI的代码需要在Handles.BeginGUI()到Handles.EndGUI()之间绘制完成。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">void</span> <span class="title">OnSceneGUI</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    Camera camera = target <span class="keyword">as</span> Camera;</span><br><span class="line">    <span class="keyword">if</span> (camera != <span class="literal">null</span>)</span><br><span class="line">    &#123;</span><br><span class="line">        Handles.color = Color.red;</span><br><span class="line">        <span class="comment">//位置信息</span></span><br><span class="line">        Handles.Label(camera.transform.position, camera.transform.position.ToString());</span><br><span class="line"></span><br><span class="line">        Handles.BeginGUI();</span><br><span class="line">        GUI.backgroundColor = Color.red;</span><br><span class="line">        <span class="keyword">if</span> (GUILayout.Button(<span class="string">&quot;click&quot;</span>, GUILayout.Width(<span class="number">200f</span>)))</span><br><span class="line">        &#123;</span><br><span class="line">            Debug.LogFormat(<span class="string">&quot;click = &#123;0&#125;&quot;</span>, camera.name);</span><br><span class="line">        &#125;</span><br><span class="line">        GUILayout.Label(<span class="string">&quot;Label&quot;</span>);</span><br><span class="line">        Handles.EndGUI();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>


<h1 id="拓展Game视图"><a href="#拓展Game视图" class="headerlink" title="拓展Game视图"></a>拓展Game视图</h1><p>分为运行模式与非运行模式。使用<code>[ExecuteInEditMode]</code>，在非运行模式下也可以执行脚本的生命周期。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">if</span> UNITY_EDITOR</span></span><br><span class="line">[<span class="meta">ExecuteInEditMode</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">Script_03_19</span> : <span class="title">MonoBehaviour</span> </span><br><span class="line">&#123;</span><br><span class="line">	<span class="function"><span class="keyword">void</span> <span class="title">OnGUI</span>()</span></span><br><span class="line">	&#123;</span><br><span class="line">		<span class="keyword">if</span> (GUILayout.Button (<span class="string">&quot;Click&quot;</span>)) &#123;</span><br><span class="line">			Debug.Log (<span class="string">&quot;click!!!&quot;</span>);</span><br><span class="line">		&#125;</span><br><span class="line">		GUILayout.Label (<span class="string">&quot;Hello World!!!&quot;</span>);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>

<h1 id="MenuItem菜单"><a href="#MenuItem菜单" class="headerlink" title="MenuItem菜单"></a>MenuItem菜单</h1><ol>
<li>MenuItem自定义菜单，与前面基本一致。</li>
<li>源生自定义菜单，在scene界面点击鼠标右键弹出，出现位置更加灵活。<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">InitializeOnLoadMethod</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">InitializeOnLoadMethod</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    SceneView.onSceneGUIDelegate = <span class="built_in">delegate</span>(SceneView sceneView) &#123;</span><br><span class="line">        Event e = Event.current;</span><br><span class="line">        <span class="comment">//鼠标右键抬起时</span></span><br><span class="line">        <span class="keyword">if</span>(e != <span class="literal">null</span> &amp;&amp; e.button ==<span class="number">1</span> &amp;&amp; e.type == EventType.MouseUp)&#123;</span><br><span class="line">            Vector2 mousePosition = e.mousePosition;</span><br><span class="line">            <span class="comment">//设置菜单项</span></span><br><span class="line">            <span class="keyword">var</span> options = <span class="keyword">new</span> GUIContent[]&#123;</span><br><span class="line">                <span class="keyword">new</span> GUIContent(<span class="string">&quot;Test1&quot;</span>),</span><br><span class="line">                <span class="keyword">new</span> GUIContent(<span class="string">&quot;Test2&quot;</span>),</span><br><span class="line">                <span class="keyword">new</span> GUIContent(<span class="string">&quot;&quot;</span>),</span><br><span class="line">                <span class="keyword">new</span> GUIContent(<span class="string">&quot;Test/Test3&quot;</span>),</span><br><span class="line">                <span class="keyword">new</span> GUIContent(<span class="string">&quot;Test/Test4&quot;</span>),   </span><br><span class="line">            &#125;;</span><br><span class="line">            <span class="comment">//设置菜单显示区域</span></span><br><span class="line">            <span class="keyword">var</span> selected= <span class="number">-1</span>;</span><br><span class="line">            <span class="keyword">var</span> userData=Selection.activeGameObject;</span><br><span class="line">            <span class="keyword">var</span> width =<span class="number">100</span>;</span><br><span class="line">            <span class="keyword">var</span> height =<span class="number">100</span>;</span><br><span class="line">            <span class="keyword">var</span> position =<span class="keyword">new</span> Rect(mousePosition.x,mousePosition.y - height,width,height);</span><br><span class="line">            <span class="comment">//显示菜单</span></span><br><span class="line">            EditorUtility.DisplayCustomMenu(position,options,selected,<span class="built_in">delegate</span>(<span class="built_in">object</span> data, <span class="built_in">string</span>[] opt, <span class="built_in">int</span> <span class="keyword">select</span>) &#123;</span><br><span class="line">                Debug.Log(opt[<span class="keyword">select</span>]);</span><br><span class="line">            &#125;,userData);</span><br><span class="line">            e.Use();</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
</ol>
<h2 id="拓展全局自定义的快捷键"><a href="#拓展全局自定义的快捷键" class="headerlink" title="拓展全局自定义的快捷键"></a>拓展全局自定义的快捷键</h2><p>自定义快捷键Command + Shift + D，将需要执行的逻辑写在方法体内。<br><code>符号相关表示如下：</code></p>
<blockquote>
<p>%：表示Windows下的Ctrl键和mac下的Command键<br> #：表示Shift键<br>&amp;：表示Alt键<br>LEFT&#x2F;RIGHT&#x2F;UP&#x2F;DOWN：表示左、右、上、下4个方向键。<br>F1…F12：表示F1至F12菜单键。</p>
</blockquote>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Assets/HotKey %#d&quot;</span>,false,-1)</span>]</span><br><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">HotKey</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    Debug.Log (<span class="string">&quot;Command Shift + D&quot;</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h1 id="面板拓展"><a href="#面板拓展" class="headerlink" title="面板拓展"></a>面板拓展</h1><h2 id="Inspector面板"><a href="#Inspector面板" class="headerlink" title="Inspector面板"></a>Inspector面板</h2><p>脚本和Editor部分可以分开。</p>
<p><img src="https://static01.imgkr.com/temp/3a4ac322968a43059b4c1c88858a9d5d.png" title="对应界面"></p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> UnityEngine;</span><br><span class="line"><span class="meta">#<span class="keyword">if</span> UNITY_EDITOR</span></span><br><span class="line"><span class="keyword">using</span> UnityEditor;</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">Script_03_23</span> :<span class="title">MonoBehaviour</span> </span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">public</span> Vector3 scrollPos;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">int</span> myId;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">string</span> myName;</span><br><span class="line">    <span class="keyword">public</span> GameObject prefab;</span><br><span class="line">    <span class="keyword">public</span> MyEnum myEnum = MyEnum.One;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">bool</span> toogle1;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">bool</span> toogle2;</span><br><span class="line">    <span class="keyword">public</span> <span class="built_in">enum</span> MyEnum</span><br><span class="line">    &#123;</span><br><span class="line">        One=<span class="number">1</span>,</span><br><span class="line">        Two,</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="keyword">if</span> UNITY_EDITOR</span></span><br><span class="line">[<span class="meta">CustomEditor(typeof(Script_03_23))</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">ScriptEditor_03_23</span> :<span class="title">Editor</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="built_in">bool</span> m_EnableToogle;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">void</span> <span class="title">OnInspectorGUI</span> ()</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//获取脚本对象</span></span><br><span class="line">        Script_03_23 script = target <span class="keyword">as</span> Script_03_23;</span><br><span class="line">        <span class="comment">//绘制滚动条</span></span><br><span class="line">        script.scrollPos =</span><br><span class="line">            EditorGUILayout.BeginScrollView(script.scrollPos,<span class="literal">false</span>,<span class="literal">true</span>);</span><br><span class="line">        </span><br><span class="line">        script.myName = EditorGUILayout.TextField (<span class="string">&quot;text&quot;</span>,script.myName);</span><br><span class="line">        script.myId = EditorGUILayout.IntField (<span class="string">&quot;int&quot;</span>, script.myId);</span><br><span class="line">        script.prefab = EditorGUILayout.ObjectField (<span class="string">&quot;GameObject&quot;</span>, script.prefab,<span class="keyword">typeof</span>(GameObject),<span class="literal">true</span>)<span class="keyword">as</span> GameObject;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//绘制按钮</span></span><br><span class="line">        EditorGUILayout.BeginHorizontal ();</span><br><span class="line">        GUILayout.Button (<span class="string">&quot;1&quot;</span>);</span><br><span class="line">        GUILayout.Button (<span class="string">&quot;2&quot;</span>);</span><br><span class="line">        script.myEnum = (Script_03_23.MyEnum)EditorGUILayout.EnumPopup(<span class="string">&quot;MyEnum:&quot;</span>, script.myEnum);</span><br><span class="line">        EditorGUILayout.EndHorizontal ();</span><br><span class="line">        <span class="comment">//Toogle组件</span></span><br><span class="line">        m_EnableToogle = EditorGUILayout.BeginToggleGroup(<span class="string">&quot;EnableToogle&quot;</span>, m_EnableToogle);</span><br><span class="line">        script.toogle1 = EditorGUILayout.Toggle(<span class="string">&quot;toogle1&quot;</span>, script.toogle1);</span><br><span class="line">        script.toogle2 = EditorGUILayout.Toggle(<span class="string">&quot;toogle2&quot;</span>, script.toogle2);</span><br><span class="line">        EditorGUILayout.EndToggleGroup();</span><br><span class="line">        EditorGUILayout.EndScrollView();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br></pre></td></tr></table></figure>
<h2 id="EditorWindows窗口"><a href="#EditorWindows窗口" class="headerlink" title="EditorWindows窗口"></a>EditorWindows窗口</h2><p>使用EditorWindow的GetWindow方法打开自定义窗口，在OnGUI方法中绘制窗口元素。<br><img src="https://static01.imgkr.com/temp/c8545ec56a8d445bb2b282b27b8ae42f.png" title="对应界面"></p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> UnityEngine;</span><br><span class="line"><span class="keyword">using</span> UnityEditor;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">Script_03_24</span> : <span class="title">EditorWindow</span> </span><br><span class="line">&#123;</span><br><span class="line">    [<span class="meta">MenuItem(<span class="string">&quot;Window/Open My Window&quot;</span>)</span>]</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Init</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Script_03_24 window = (Script_03_24)EditorWindow.GetWindow(<span class="keyword">typeof</span>(Script_03_24));</span><br><span class="line">        window.Show();</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">private</span> Texture m_MyTexture = <span class="literal">null</span>;</span><br><span class="line">    <span class="keyword">private</span> <span class="built_in">float</span> m_MyFloat = <span class="number">0.5f</span>;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">Awake</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Debug.LogFormat (<span class="string">&quot;窗口初始化时调用&quot;</span>);</span><br><span class="line">        m_MyTexture = AssetDatabase.LoadAssetAtPath&lt;Texture&gt; (<span class="string">&quot;Assets/unity.png&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnGUI</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        GUILayout.Label(<span class="string">&quot;Hello World!!&quot;</span>, EditorStyles.boldLabel);</span><br><span class="line">        m_MyFloat = EditorGUILayout.Slider(<span class="string">&quot;Slider&quot;</span>, m_MyFloat, <span class="number">-5</span>, <span class="number">5</span>);</span><br><span class="line">        GUI.DrawTexture(<span class="keyword">new</span> Rect(<span class="number">0</span>,<span class="number">30</span>,<span class="number">100</span>,<span class="number">100</span>),m_MyTexture);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnDestroy</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Debug.LogFormat (<span class="string">&quot;窗口销毁时调用&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnFocus</span>()</span>&#123;</span><br><span class="line">        Debug.LogFormat (<span class="string">&quot;窗口拥有焦点时调用&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnHierarchyChange</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Debug.LogFormat (<span class="string">&quot;Hierarchy视图发生改变时调用&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnInspectorUpdate</span> ()</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//Debug.LogFormat (&quot;Inspector每帧更新&quot;);</span></span><br><span class="line">    &#125;   </span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnLostFocus</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Debug.LogFormat (<span class="string">&quot;失去焦点&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnProjectChange</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Debug.LogFormat (<span class="string">&quot;Project视图发生改变时调用&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnSelectionChange</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Debug.LogFormat (<span class="string">&quot;Hierarchy或者Project视图中选择一个对象时调用&quot;</span>);</span><br><span class="line">    &#125;   </span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">Update</span> ()</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">//Debug.LogFormat (&quot;每帧更新&quot;);</span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="EditorWindows窗口的下拉菜单"><a href="#EditorWindows窗口的下拉菜单" class="headerlink" title="EditorWindows窗口的下拉菜单"></a>EditorWindows窗口的下拉菜单</h2><p>需要<code>实现IHasCustomMenu接口</code>,通过AddItem方法添加列表元素。<br><img src="https://static01.imgkr.com/temp/0e2b51442ee4447a9af7d86d5db1e42c.png" title="对应界面"></p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">Script_03_25</span> : <span class="title">EditorWindow</span> ,<span class="title">IHasCustomMenu</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="meta">#<span class="keyword">region</span> IHasCustomMenu implementation</span></span><br><span class="line">    <span class="keyword">void</span> IHasCustomMenu.AddItemsToMenu (GenericMenu menu)</span><br><span class="line">    &#123;</span><br><span class="line">        menu.AddDisabledItem (<span class="keyword">new</span> GUIContent (<span class="string">&quot;Disable&quot;</span>));</span><br><span class="line">        menu.AddItem (<span class="keyword">new</span> GUIContent (<span class="string">&quot;Test1&quot;</span>), <span class="literal">true</span>, ()=&gt; &#123;</span><br><span class="line">            Debug.Log(<span class="string">&quot;Test1&quot;</span>);</span><br><span class="line">        &#125;);</span><br><span class="line">        menu.AddItem (<span class="keyword">new</span> GUIContent (<span class="string">&quot;Test2&quot;</span>), <span class="literal">true</span>, ()=&gt; &#123;</span><br><span class="line">            Debug.Log(<span class="string">&quot;Test2&quot;</span>);</span><br><span class="line">        &#125;);</span><br><span class="line">        menu.AddSeparator (<span class="string">&quot;Test/&quot;</span>);</span><br><span class="line">        menu.AddItem (<span class="keyword">new</span> GUIContent (<span class="string">&quot;Test/Tes3&quot;</span>), <span class="literal">true</span>, ()=&gt; &#123;</span><br><span class="line">            Debug.Log(<span class="string">&quot;Tes3&quot;</span>);</span><br><span class="line">        &#125;);</span><br><span class="line">    </span><br><span class="line">    &#125;</span><br><span class="line">    <span class="meta">#<span class="keyword">endregion</span></span></span><br><span class="line">    [<span class="meta">MenuItem(<span class="string">&quot;Window/Open My Window&quot;</span>)</span>]</span><br><span class="line">    <span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Init</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        Script_03_25 window = (Script_03_25)EditorWindow.GetWindow(<span class="keyword">typeof</span>(Script_03_25));</span><br><span class="line">        window.Show();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="预览窗口"><a href="#预览窗口" class="headerlink" title="预览窗口"></a>预览窗口</h2><p>继承ObjectPreview并<code>重写OnPreviewGUI方法</code>。选择游戏对象或游戏资源后，inspector面板下会出现它的预览窗口。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">CustomPreview(typeof(GameObject))</span>]</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">Script_03_25</span> :<span class="title">ObjectPreview</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">override</span> <span class="built_in">bool</span> <span class="title">HasPreviewGUI</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">override</span> <span class="keyword">void</span> <span class="title">OnPreviewGUI</span>(<span class="params">Rect r, GUIStyle background</span>)</span></span><br><span class="line">    &#123;</span><br><span class="line">        GUI.DrawTexture(r,AssetDatabase.LoadAssetAtPath&lt;Texture&gt;(<span class="string">&quot;Assets/unity.png&quot;</span>));</span><br><span class="line">        GUILayout.Label (<span class="string">&quot;Hello World!!!&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="清空控制台日志"><a href="#清空控制台日志" class="headerlink" title="清空控制台日志"></a>清空控制台日志</h2><p>通过反射实现，LogEntries类为密封类。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Tools/CreateConsole&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">CreateConsole</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    Debug.Log (<span class="string">&quot;CreateConsole&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line">[<span class="meta">MenuItem(<span class="string">&quot;Tools/CleanConsole&quot;</span>)</span>]</span><br><span class="line"><span class="function"><span class="keyword">static</span> <span class="keyword">void</span> <span class="title">CleanConsole</span>()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="comment">//获取assembly</span></span><br><span class="line">    Assembly assembly = Assembly.GetAssembly (<span class="keyword">typeof</span>(Editor));</span><br><span class="line">    <span class="comment">//反射获取LogEntries对象</span></span><br><span class="line">    MethodInfo methodInfo = assembly.GetType(<span class="string">&quot;UnityEditor.LogEntries&quot;</span>).</span><br><span class="line">        GetMethod(<span class="string">&quot;Clear&quot;</span>);</span><br><span class="line">    <span class="comment">//调用Clear方法</span></span><br><span class="line">    methodInfo.Invoke(<span class="keyword">new</span> <span class="built_in">object</span>(), <span class="literal">null</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="获取EditorStyles样式"><a href="#获取EditorStyles样式" class="headerlink" title="获取EditorStyles样式"></a>获取EditorStyles样式</h2><p>EditorStyles是编辑器用到的样式，但是Unity文档中没有集中说明每个样式对应的效果。<br>通过反射获取EditorStyles下的所有样式，然后在窗口中依次绘制出来。其中，<code>BindingFlags</code>表示反射属性的类型。<br>在制作编辑器时，可以直接通过这些Style名字选择对应的样式。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">using</span> UnityEngine;</span><br><span class="line"><span class="keyword">using</span> UnityEditor;</span><br><span class="line"><span class="keyword">using</span> System.Reflection;</span><br><span class="line"><span class="keyword">using</span> System.Collections.Generic;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">Script_03_29</span> :<span class="title">EditorWindow</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">static</span> List&lt;GUIStyle&gt; styles = <span class="literal">null</span>;</span><br><span class="line">    [<span class="meta">MenuItem(<span class="string">&quot;Window/Open My Window&quot;</span>)</span>]</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">Test</span>()</span> &#123;</span><br><span class="line">        EditorWindow.GetWindow&lt;Script_03_29&gt;(<span class="string">&quot;styles&quot;</span>);</span><br><span class="line"></span><br><span class="line">        styles = <span class="keyword">new</span> List&lt;GUIStyle&gt; (); </span><br><span class="line">        <span class="keyword">foreach</span>(<span class="function">PropertyInfo fi <span class="keyword">in</span> <span class="title">typeof</span>(<span class="params">EditorStyles</span>).<span class="title">GetProperties</span>(<span class="params">BindingFlags.Static|BindingFlags.Public|BindingFlags.NonPublic</span>))</span></span><br><span class="line">        &#123;</span><br><span class="line">            <span class="built_in">object</span> o = fi.GetValue (<span class="literal">null</span>, <span class="literal">null</span>);</span><br><span class="line">            <span class="keyword">if</span> (o.GetType () == <span class="keyword">typeof</span>(GUIStyle)) &#123;</span><br><span class="line">                styles.Add (o <span class="keyword">as</span> GUIStyle);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> Vector2 scrollPosition = Vector2.zero;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnGUI</span>()</span> </span><br><span class="line">    &#123;</span><br><span class="line">        scrollPosition = GUILayout.BeginScrollView (scrollPosition);</span><br><span class="line">        <span class="keyword">for</span> (<span class="built_in">int</span> i = <span class="number">0</span>; i &lt; styles.Count; i++) &#123;</span><br><span class="line">            GUILayout.Label (<span class="string">&quot;EditorStyles.&quot;</span> +styles[i].name , styles[i]);</span><br><span class="line">        &#125;</span><br><span class="line">        GUILayout.EndScrollView ();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="获取内置图标样式"><a href="#获取内置图标样式" class="headerlink" title="获取内置图标样式"></a>获取内置图标样式</h2><p>首先通过<code>Resources.FindObjectsOfTypeAll</code>方法查找出所有贴图，然后通过<code>EditorGUIUtility.IconContent</code>方法加载引擎所用到的图标。</p>
<figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title">Script_03_30</span> :<span class="title">EditorWindow</span></span><br><span class="line">&#123;</span><br><span class="line">    [<span class="meta">MenuItem(<span class="string">&quot;Window/Open My Window&quot;</span>)</span>]</span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">OpenMyWindow</span>()</span> &#123;</span><br><span class="line">        EditorWindow.GetWindow&lt;Script_03_30&gt;(<span class="string">&quot;icons&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">private</span> Vector2 m_Scroll;</span><br><span class="line">    <span class="keyword">private</span> List&lt;<span class="built_in">string</span>&gt; m_Icons = <span class="literal">null</span>;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">Awake</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        m_Icons = <span class="keyword">new</span> List&lt;<span class="built_in">string</span>&gt; ();;</span><br><span class="line">        Texture2D[] t = Resources.FindObjectsOfTypeAll&lt;Texture2D&gt;();</span><br><span class="line">        <span class="keyword">foreach</span> (Texture2D x <span class="keyword">in</span> t) &#123;</span><br><span class="line">            Debug.unityLogger.logEnabled = <span class="literal">false</span>;</span><br><span class="line">            GUIContent gc = EditorGUIUtility.IconContent(x.name);</span><br><span class="line">            Debug.unityLogger.logEnabled = <span class="literal">true</span>;</span><br><span class="line">            <span class="keyword">if</span> (gc != <span class="literal">null</span> &amp;&amp; gc.image != <span class="literal">null</span>) &#123;</span><br><span class="line">                m_Icons.Add (x.name);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        Debug.Log (m_Icons.Count);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">OnGUI</span>()</span></span><br><span class="line">    &#123;</span><br><span class="line">        m_Scroll = GUILayout.BeginScrollView (m_Scroll);</span><br><span class="line">        <span class="built_in">float</span> width = <span class="number">50f</span>;</span><br><span class="line">        <span class="built_in">int</span> count = (<span class="built_in">int</span>)(position.width / width);</span><br><span class="line">        <span class="keyword">for</span>(<span class="built_in">int</span> i =<span class="number">0</span>; i&lt; m_Icons.Count; i += count)</span><br><span class="line">        &#123;</span><br><span class="line">            GUILayout.BeginHorizontal();</span><br><span class="line">            <span class="keyword">for</span> (<span class="built_in">int</span> j =<span class="number">0</span>; j &lt; count; j++)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="built_in">int</span> index = i + j;</span><br><span class="line">                <span class="keyword">if</span>(index &lt; m_Icons.Count)</span><br><span class="line">                    GUILayout.Button(EditorGUIUtility.IconContent(m_Icons[index]), GUILayout.Width(width), GUILayout.Height(<span class="number">30</span>));</span><br><span class="line">            &#125;</span><br><span class="line">            GUILayout.EndHorizontal();</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        EditorGUILayout.EndScrollView();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<blockquote>
<p>其它资料<br><a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/109328430">https://zhuanlan.zhihu.com/p/109328430</a><br><a target="_blank" rel="noopener" href="https://www.lfzxb.top/unity-editor-extension-base/">https://www.lfzxb.top/unity-editor-extension-base/</a><br><a target="_blank" rel="noopener" href="https://www.lfzxb.top/unity-editor-crash-course/#%E5%89%8D%E8%A8%80">https://www.lfzxb.top/unity-editor-crash-course/#%E5%89%8D%E8%A8%80</a></p>
</blockquote>
<p><code>待补充。。</code></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://hotarunohikari.gitee.io/hotaru-no-hikari">螢の光</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://hotarunohikari.gitee.io/hotaru-no-hikari/2021/10/24/%E5%88%9D%E6%AD%A5%E4%BA%86%E8%A7%A3%E7%BC%96%E8%BE%91%E5%99%A8%E6%8B%93%E5%B1%95/">https://hotarunohikari.gitee.io/hotaru-no-hikari/2021/10/24/%E5%88%9D%E6%AD%A5%E4%BA%86%E8%A7%A3%E7%BC%96%E8%BE%91%E5%99%A8%E6%8B%93%E5%B1%95/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://hotarunohikari.gitee.io/hotaru-no-hikari" target="_blank">Hotaru Hikari's Blog</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/hotaru-no-hikari/tags/Unity/">Unity</a><a class="post-meta__tags" href="/hotaru-no-hikari/tags/%E7%BC%96%E8%BE%91%E5%99%A8%E6%8B%93%E5%B1%95/">编辑器拓展</a></div><div class="post_share"><div class="social-share" data-image="/hotaru-no-hikari/img/cover2.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/gh/overtrue/share.js@master/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/hotaru-no-hikari/2021/10/25/%E7%A0%B4%E6%99%93%E4%BC%A0%E8%AF%B4%E9%80%9A%E5%85%B3%E6%84%9F%E6%83%B3/"><img class="prev-cover" src="/hotaru-no-hikari/img/BG/3.jpg" onerror="onerror=null;src='/hotaru-no-hikari/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">破晓传说通关感想</div></div></a></div><div class="next-post pull-right"><a href="/hotaru-no-hikari/2021/10/24/OpenCVForUnity/"><img class="next-cover" src="/hotaru-no-hikari/img/cover2.jpg" onerror="onerror=null;src='/hotaru-no-hikari/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">OpenCV在Unity中的简单运用</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/hotaru-no-hikari/2021/10/24/OpenCVForUnity/" title="OpenCV在Unity中的简单运用"><img class="cover" src="/hotaru-no-hikari/img/cover2.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-24</div><div class="title">OpenCV在Unity中的简单运用</div></div></a></div><div><a href="/hotaru-no-hikari/2021/10/28/%E4%BD%BF%E7%94%A8await%E3%80%81aysnc/" title="在Unity中使用async和await"><img class="cover" src="/hotaru-no-hikari/img/cover2.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-28</div><div class="title">在Unity中使用async和await</div></div></a></div><div><a href="/hotaru-no-hikari/2021/10/27/%E5%9C%A8Unity%E4%B8%AD%E4%BD%BF%E7%94%A8System.Drawing%E7%94%9F%E6%88%90%E9%AA%8C%E8%AF%81%E7%A0%81/" title="在Unity中使用Bitmap生成验证码图片"><img class="cover" src="/hotaru-no-hikari/img/cover2.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-10-27</div><div class="title">在Unity中使用Bitmap生成验证码图片</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/hotaru-no-hikari/img/avatar.jpg" onerror="this.onerror=null;this.src='/hotaru-no-hikari/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">螢の光</div><div class="author-info__description">游戏开发者成长日志</div></div><div class="card-info-data site-data is-center"><a href="/hotaru-no-hikari/archives/"><div class="headline">文章</div><div class="length-num">9</div></a><a href="/hotaru-no-hikari/tags/"><div class="headline">标签</div><div class="length-num">9</div></a><a href="/hotaru-no-hikari/categories/"><div class="headline">分类</div><div class="length-num">13</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/HotaruHikari"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/HotaruHikari" target="_blank" title="Github"><i class="ri-home-wifi-line"></i></a><a class="social-icon" href="mailto:728831102@qq.com" target="_blank" title="Email"><i class="fa-solid fa-house-laptop"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8B%93%E5%B1%95Project%E8%A7%86%E5%9B%BE"><span class="toc-number">1.</span> <span class="toc-text">拓展Project视图</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8B%93%E5%B1%95Project"><span class="toc-number">1.1.</span> <span class="toc-text">拓展Project</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AF%B9Create%E8%BF%9B%E8%A1%8C%E6%8B%93%E5%B1%95"><span class="toc-number">1.2.</span> <span class="toc-text">对Create进行拓展</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%83%E5%B1%80%E6%8B%93%E5%B1%95"><span class="toc-number">1.3.</span> <span class="toc-text">布局拓展</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8B%93%E5%B1%95Hierarchy%E8%A7%86%E5%9B%BE"><span class="toc-number">2.</span> <span class="toc-text">拓展Hierarchy视图</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8B%93%E5%B1%95%E8%8F%9C%E5%8D%95"><span class="toc-number">2.1.</span> <span class="toc-text">拓展菜单</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8B%93%E5%B1%95%E5%B8%83%E5%B1%80"><span class="toc-number">2.2.</span> <span class="toc-text">拓展布局</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%87%8D%E5%86%99%E8%8F%9C%E5%8D%95"><span class="toc-number">2.3.</span> <span class="toc-text">重写菜单</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%87%8D%E5%86%99%E8%87%AA%E5%B8%A6%E7%9A%84Image%E7%BB%84%E4%BB%B6"><span class="toc-number">2.4.</span> <span class="toc-text">重写自带的Image组件</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8B%93%E5%B1%95Inspector%E8%A7%86%E5%9B%BE"><span class="toc-number">3.</span> <span class="toc-text">拓展Inspector视图</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8B%93%E5%B1%95%E6%BA%90%E7%94%9F%E7%BB%84%E4%BB%B6"><span class="toc-number">3.1.</span> <span class="toc-text">拓展源生组件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8B%93%E5%B1%95%E7%BB%A7%E6%89%BF%E7%BB%84%E4%BB%B6"><span class="toc-number">3.2.</span> <span class="toc-text">拓展继承组件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E4%B8%8D%E5%8F%AF%E7%BC%96%E8%BE%91"><span class="toc-number">3.3.</span> <span class="toc-text">组件不可编辑</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Context%E8%8F%9C%E5%8D%95"><span class="toc-number">3.4.</span> <span class="toc-text">Context菜单</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8B%93%E5%B1%95Scene%E8%A7%86%E5%9B%BE"><span class="toc-number">4.</span> <span class="toc-text">拓展Scene视图</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BE%85%E5%8A%A9%E5%85%83%E7%B4%A0"><span class="toc-number">4.1.</span> <span class="toc-text">辅助元素</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%BE%85%E5%8A%A9UI"><span class="toc-number">4.2.</span> <span class="toc-text">辅助UI</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E6%8B%93%E5%B1%95Game%E8%A7%86%E5%9B%BE"><span class="toc-number">5.</span> <span class="toc-text">拓展Game视图</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#MenuItem%E8%8F%9C%E5%8D%95"><span class="toc-number">6.</span> <span class="toc-text">MenuItem菜单</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8B%93%E5%B1%95%E5%85%A8%E5%B1%80%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E5%BF%AB%E6%8D%B7%E9%94%AE"><span class="toc-number">6.1.</span> <span class="toc-text">拓展全局自定义的快捷键</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E9%9D%A2%E6%9D%BF%E6%8B%93%E5%B1%95"><span class="toc-number">7.</span> <span class="toc-text">面板拓展</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#Inspector%E9%9D%A2%E6%9D%BF"><span class="toc-number">7.1.</span> <span class="toc-text">Inspector面板</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#EditorWindows%E7%AA%97%E5%8F%A3"><span class="toc-number">7.2.</span> <span class="toc-text">EditorWindows窗口</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#EditorWindows%E7%AA%97%E5%8F%A3%E7%9A%84%E4%B8%8B%E6%8B%89%E8%8F%9C%E5%8D%95"><span class="toc-number">7.3.</span> <span class="toc-text">EditorWindows窗口的下拉菜单</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A2%84%E8%A7%88%E7%AA%97%E5%8F%A3"><span class="toc-number">7.4.</span> <span class="toc-text">预览窗口</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B8%85%E7%A9%BA%E6%8E%A7%E5%88%B6%E5%8F%B0%E6%97%A5%E5%BF%97"><span class="toc-number">7.5.</span> <span class="toc-text">清空控制台日志</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96EditorStyles%E6%A0%B7%E5%BC%8F"><span class="toc-number">7.6.</span> <span class="toc-text">获取EditorStyles样式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E8%8E%B7%E5%8F%96%E5%86%85%E7%BD%AE%E5%9B%BE%E6%A0%87%E6%A0%B7%E5%BC%8F"><span class="toc-number">7.7.</span> <span class="toc-text">获取内置图标样式</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/hotaru-no-hikari/2022/06/07/hello-world/" title="Hello World"><img src="/hotaru-no-hikari/img/cover2.jpg" onerror="this.onerror=null;this.src='/hotaru-no-hikari/img/404.jpg'" alt="Hello World"/></a><div class="content"><a class="title" href="/hotaru-no-hikari/2022/06/07/hello-world/" title="Hello World">Hello World</a><time datetime="2022-06-07T10:58:52.802Z" title="发表于 2022-06-07 18:58:52">2022-06-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hotaru-no-hikari/2021/10/30/%E7%A7%8B%E6%8B%9B%E6%80%BB%E7%BB%93/" title="简单的秋招总结"><img src="/hotaru-no-hikari/img/cover2.jpg" onerror="this.onerror=null;this.src='/hotaru-no-hikari/img/404.jpg'" alt="简单的秋招总结"/></a><div class="content"><a class="title" href="/hotaru-no-hikari/2021/10/30/%E7%A7%8B%E6%8B%9B%E6%80%BB%E7%BB%93/" title="简单的秋招总结">简单的秋招总结</a><time datetime="2021-10-30T03:45:48.000Z" title="发表于 2021-10-30 11:45:48">2021-10-30</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hotaru-no-hikari/2021/10/28/%E4%BD%BF%E7%94%A8await%E3%80%81aysnc/" title="在Unity中使用async和await"><img src="/hotaru-no-hikari/img/cover2.jpg" onerror="this.onerror=null;this.src='/hotaru-no-hikari/img/404.jpg'" alt="在Unity中使用async和await"/></a><div class="content"><a class="title" href="/hotaru-no-hikari/2021/10/28/%E4%BD%BF%E7%94%A8await%E3%80%81aysnc/" title="在Unity中使用async和await">在Unity中使用async和await</a><time datetime="2021-10-28T08:31:50.000Z" title="发表于 2021-10-28 16:31:50">2021-10-28</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hotaru-no-hikari/2021/10/27/%E5%9C%A8Unity%E4%B8%AD%E4%BD%BF%E7%94%A8System.Drawing%E7%94%9F%E6%88%90%E9%AA%8C%E8%AF%81%E7%A0%81/" title="在Unity中使用Bitmap生成验证码图片"><img src="/hotaru-no-hikari/img/cover2.jpg" onerror="this.onerror=null;this.src='/hotaru-no-hikari/img/404.jpg'" alt="在Unity中使用Bitmap生成验证码图片"/></a><div class="content"><a class="title" href="/hotaru-no-hikari/2021/10/27/%E5%9C%A8Unity%E4%B8%AD%E4%BD%BF%E7%94%A8System.Drawing%E7%94%9F%E6%88%90%E9%AA%8C%E8%AF%81%E7%A0%81/" title="在Unity中使用Bitmap生成验证码图片">在Unity中使用Bitmap生成验证码图片</a><time datetime="2021-10-27T05:50:09.000Z" title="发表于 2021-10-27 13:50:09">2021-10-27</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/hotaru-no-hikari/2021/10/25/%E7%A0%B4%E6%99%93%E4%BC%A0%E8%AF%B4%E9%80%9A%E5%85%B3%E6%84%9F%E6%83%B3/" title="破晓传说通关感想"><img src="/hotaru-no-hikari/img/BG/3.jpg" onerror="this.onerror=null;this.src='/hotaru-no-hikari/img/404.jpg'" alt="破晓传说通关感想"/></a><div class="content"><a class="title" href="/hotaru-no-hikari/2021/10/25/%E7%A0%B4%E6%99%93%E4%BC%A0%E8%AF%B4%E9%80%9A%E5%85%B3%E6%84%9F%E6%83%B3/" title="破晓传说通关感想">破晓传说通关感想</a><time datetime="2021-10-25T12:45:48.000Z" title="发表于 2021-10-25 20:45:48">2021-10-25</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2021 - 2022 By 螢の光</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/hotaru-no-hikari/js/utils.js"></script><script src="/hotaru-no-hikari/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>